/**
* 模版
**/ 

<template>
  <el-container>
    <el-header>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>{{title[0]}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{title[1]}}</el-breadcrumb-item>
      </el-breadcrumb>
      <h3>{{title[1]}}</h3>

    </el-header>
    <el-main>
      <div class="addQ">
        <el-form ref="form"
                 :model="form"
                 size="large">
          <h1>考试基本信息：</h1>
          <el-form-item label="*考试名称">
            <el-input v-model="form.name"
                      style="width:50%"></el-input>
          </el-form-item>
          <el-form-item label="*考试时间">
            <div class="block">
              <span class="demonstration"></span>
              <el-date-picker v-model="form.startTime"
                              type="datetime"
                              placeholder="选择日期时间"
                              style="width:24%">
              </el-date-picker>
              -
              <el-date-picker v-model="form.endTime"
                              type="datetime"
                              placeholder="选择日期时间"
                              style="width:25%">
              </el-date-picker>
            </div>
          </el-form-item>
          <el-form-item label="考试科目">

            <el-select v-model="form.sub"
                       placeholder="请选择科目"
                       style="width:16%">
              <el-option v-for="subb in allSub"
                         :value="subb"
                         :key="subb"></el-option>

            </el-select>
            *答题时间(分钟):<el-input v-model="form.doTime"
                      style="width:26%"></el-input>
          </el-form-item>
          <el-form-item label="*考试说明">
            <el-input type="textarea"
                      v-model="form.des"
                      style="width:50.5%"></el-input>
          </el-form-item>
          <el-form-item label="参考班级">
            <el-transfer v-model="form.classs"
                         :data="classdata"
                         :titles="['所有班级', '所选班级']"></el-transfer>
          </el-form-item>
          <h1>试卷信息:</h1>
          <el-form-item>
            <span class="demonstration">选择试卷</span>

            <el-select v-model="form.paperId"
                       filterable
                       placeholder="请选择">
              <el-option v-for="paper in allPaper"
                         :value="paper.id"
                         :key="paper.name"
                         :label="paper.name"></el-option>

            </el-select>
          </el-form-item>
          <el-form-item>
            试题排序:&nbsp;&nbsp;&nbsp;&nbsp;

            <el-switch v-model="form.topOrder"
                       active-text="固定"
                       inactive-text="随机">
            </el-switch>

          </el-form-item>
          <el-form-item>
            选项排序:&nbsp;&nbsp;&nbsp;&nbsp;
            <el-switch v-model="form.optOrder"
                       active-text="固定"
                       inactive-text="随机">
            </el-switch>
          </el-form-item>
          <el-form-item>
            及格分数(百分比):
            <el-input v-model="form.okScore"
                      style="width:5%"></el-input>%

          </el-form-item>
          <div>
            <el-form-item>
              单选数量：
              <el-input-number v-model="form.exclusive"
                               @change="handleChange"
                               :min="0"
                               :max="20"
                               label="单选数量"></el-input-number>
              多选数量：
              <el-input-number v-model="form.multiple"
                               @change="handleChange"
                               :min="0"
                               :max="20"
                               label="多选数量"
                               display=inline-block></el-input-number>
              阅读数量：
              <el-input-number v-model="form.read"
                               @change="handleChange"
                               :min="0"
                               :max="20"
                               label="阅读数量"></el-input-number>
            </el-form-item>
          </div>
          <el-form-item size="large">
            <el-button type="primary"
                       @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import { findGrade, findSub } from '../../api/questionMG'
import { tList, addTest, testList } from '../../api/testMG'
import { getCookie } from '../../utils/util'
import { findAllC } from '../../api/class'
import { findPaper } from '../../api/paperMG'
export default {
  data() {
    return {
      form: {
        user: '',
        sub: '',
        name: '',
        doTime: '',
        des: '',
        startTime: '',
        endTime: '',
        exclusive: '1',
        multiple: '1',
        read: '1',
        classs: [],
        topOrder: 'true',
        optOrder: 'true',
        okScore: '',
        paperId: '',
      },
      allPaper: [],
      allClass: [],
      classdata: [],
      allSub: [],
      papers: [{ value: 'zhinan', label: '指南' }],
    }
  },
  methods: {
    onSubmit() {
      addTest(this.form).then((res) => {
        //console.log(res.data)
        if (res.data.code == 200) {
          //console.log(res.data.code)
          alert('添加成功')
        }
      })
    },

    handleChange() {},
  },
  created() {
    this.form.user = JSON.parse(localStorage.getItem('userdata')).data.id
    ;(this.title = this.$route.name.split('/')),
      findSub().then((res) => {
        this.allSub = res.data
      })
    findPaper().then((res) => {
      this.allPaper = res.data.data
      console.log(this.allPaper)
    })
    findAllC().then((res) => {
      this.allClass = res.data

      for (let i = 0; i < res.data.length; i++) {
        this.classdata.push({
          key: this.allClass[i].class_id,
          label: this.allClass[i].class_name,
        })
      }
    })
  },
}
</script>
<style>
</style>
